﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Linguist.Util
{
    /// <summary>
    /// An LRU cache
    /// </summary>
    /// <typeparam name="K"></typeparam>
    /// <typeparam name="V"></typeparam>
    public class LRUCache<K, V>:Dictionary<K, V> 
    {

        int maxSize;


        /**
        /// Creates an LRU cache with the given maximum size
         *
        /// @param maxSize the maximum size of the cache
         */
        public LRUCache(int maxSize) 
        {
            this.maxSize = maxSize;
        }


        /**
        /// Determines if the eldest entry in the map should be removed.
         *
        /// @param eldest the eldest entry
        /// @return true if the eldest entry should be removed
         */
        
        protected Boolean removeEldestEntry(KeyValuePair<K,V> eldest) 
        {
            return Count > maxSize;
        }
    }

}
